import QtWebSockets 1.15

WebSocket{
    id:socket
    url:"ws://localhost:8090"
    active: true

    //收到消息




    //发送消息
    /*
        {"code":10002,"nickname":"系统联通测试消息","userid":111,"type":1,"fromId":111,"msgId":"asdhjkashdjk","phone":"17760659134","msgcontent":"你好嘛 宝贝?","nickname":"金箍棒","toId":111}
    */

    function sedMessage(code,nickname,userid,type,fromId,msgId,phone,msgcontent,nickname,toId){
        var msgInfo={
            code:code,
            nickname:nickname,
            userid:userid,
            type:type,
            fromId:fromId,
            msgId:msgId,
            phone:phone,
            msgcontent:msgcontent,
            nickname:nickname,
            toId:toId
        }

        socket.sendTextMessage(JSON.stringify(msgInfo))

    }
    onStatusChanged: {
        // console.log(socket.errorString)
        // console.log(socket.status)
        // console.log(socket.status==WebSocket.Open)
        if(socket.status==WebSocket.Open){
            //建立链接成功,立刻测试
            socket.sendTextMessage(JSON.stringify( {"code":10001,"nickname":"系统联通测试消息","userid":111}))
        }
    }

}
